const mongoose = require("mongoose");
module.exports.getAllUsers3 = async ({ currentPage, pageSize }) => {
    const total = await mongoose.model("userModel").countDocuments();//用户数据总条数
    const pages = Math.ceil(total / pageSize);//计算用户列表总页数
    const usersData = await mongoose.model("userModel")
        .find()
        .populate("collections")//关联收藏
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    return { total, pages, usersData };
}

module.exports.getUnnamedUsers3 = async ({ currentPage, pageSize, idcard }) => {
    const search = await mongoose.model("userModel").find({ idcard });
    const total = search.length;//分类用户数据总条数
    const pages = Math.ceil(total / pageSize);//计算用户列表总页数
    const usersData = await mongoose.model("userModel")
        .find({ idcard })
        .populate("collections")//关联收藏
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    return { total, pages, usersData };
}
module.exports.getUnpassUsers3 = async ({ currentPage, pageSize, lessor }) => {
    const search = await mongoose.model("userModel").find({ lessor });
    const total = search.length;//分类用户数据总条数
    const pages = Math.ceil(total / pageSize);//计算用户列表总页数
    const usersData = await mongoose.model("userModel")
        .find({ lessor })
        .populate("collections")//关联收藏
        .limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    return { total, pages, usersData };
}
module.exports.getOneUser3 = async ({ _id }) => {
    return await mongoose.model("userModel").find({ _id })
}

module.exports.pass3 = async ({ _id, lessor }) => {
    return await mongoose.model("userModel").updateOne({ _id }, { lessor });
}

module.exports.getuser3 = async (res, req) => {
    const usersData = await mongoose.model("userModel").find()
    return { usersData };
}
module.exports.login3 = async(user)=>{
    return await mongoose.model("userModel").find(user);
}
module.exports.regist3 = async({account,password})=>{
    return await mongoose.model("userModel").create({account,password})
}
